//
//  ShellExchangeViewModel.m
//  ShellWallert
//
//  Created by lvzhao on 2020/2/15.
//  Copyright © 2020 VV. All rights reserved.
//

#import "ShellExchangeViewModel.h"

@implementation ShellExchangeViewModel
- (instancetype)init
{
    self = [super init];
    if (self) {
        self.symbol = @"usdteth";
        self.currentCurrncy = @"USDT";

    }
    return self;
}

/**
 Convert 請求闪兑的配置參數
 */
- (void)getExchangeConfig{
    
    @weakify(self);
    [LZNetworkingManager lz_request:@"get" url:kExchangeRate params:@{@"symbol":self.symbol?:@""} success:^(id  _Nullable responseObject) {
        @strongify(self);
        if([responseObject[kResultStatus] isEqualToString:kCode]){
            self.configDictionary = responseObject;
        }
        [self.reloadSubject sendNext:@(1)];
    } failure:^(NSError * _Nullable error) {}isLoading:YES isFailTip:YES];
    
}

/**
 Convert   發起對兌換
 @param symbol USDT兑换ETH：usdteth   ETH兑换USDT：ethusdt
 @param amount  数量
 */
- (void) startExchange:(NSString *)symbol
               verCode:(NSString *)amount{
    
    NSDictionary *params = @{@"symbol":self.symbol,
                             @"amount":amount?:@""};
    
    @weakify(self);
    [LZNetworkingManager lz_request:@"post" url:kExchange params:params success:^(id  _Nullable responseObject) {
        @strongify(self);
        if([responseObject[kResultStatus] isEqualToString:kCode]){
            //兑换成功
            NSString *number = [NSString stringWithFormat:@"%@",responseObject[kResultData]];
            NSString *message = @"";
            if([self.currentCurrncy isEqualToString:@"USDT"]){
                message = [NSString stringWithFormat:LZLocalizedString(@"账户增加 %@ %@"),number,@"ETH"];
            } else {
                message = [NSString stringWithFormat:LZLocalizedString(@"账户增加 %@ %@"),number,@"USDT"];
            }
            [LZToolView showAlertType:LZAlertViewTypeLiquidation withTitle:LZLocalizedString(@"闪兑成功") message:message cancel:@"" sure:LZLocalizedString(@"确定") objectDict:@{@"":@""} cancelBlock:^(id  _Nullable object) { } sureBlock:^(id  _Nullable object) {
                
                [LZTool.currentViewController.navigationController popToRootViewControllerAnimated:YES];
                
            }];
        }
    } failure:^(NSError * _Nullable error) {}isLoading:YES isFailTip:YES];
}
@end
